<?php

/**
 *
 * @export User
 * @export-metadata singleinstance
 */
class JPrincipal extends Principal {

    /**
     * @var JUser
     */
    private $jUser;

    function __construct() {
        parent::__construct();
        $this->jUser = JFactory::getUser();
        $this->setName($this->jUser->username);
        $this->setCredential($this->jUser->password);

        if (!$this->isAnonimous()) {
            $session = JFactory::getSession();
            $this->getData()->add("token", $session->get("token"));
            $this->setPermissions($session->get("roles"));
        }
    }

    public function isAnonimous() {
        return $this->jUser->guest;
    }

}

?>
